<template>
    <div class="right">
        <div class="header">会员中心-我的收藏</div>
        <div class="content">
            <div class="tabs">
                <div v-for="(item, index) in navList" :key="index" @click="navClick(item)"
                    :class="navIndex == item.label ? 'tabs_items_active' : 'tabs_items'">
                    {{ item.label }}
                </div>
            </div>
            <div class="contents" v-loading="loading">
                <div class="items" v-for="(item, index) in list" :key="index">
                    <image-preview :src="item.avatarImage" :width="50" :height="50" />
                    <div class="right">
                        <div class="title">{{ item.title }}</div>
                        <div class="bottom">
                            <div class="hits">{{ item.hits }}</div>
                            <div class="createTime">{{ item.createTime }}</div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="paginations">
                <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum"
                    v-model:limit="queryParams.pageSize" @pagination="getList" :layout="'prev, pager, next'"
                    :prevText="'上一页'" :nextText="'下一页'" />
            </div>
        </div>
    </div>
</template>
<script setup lang="ts">
import { collectList } from '@/api/index'
const list = ref([])
const navList = ref([
    { label: '所有', value: '' },
    { label: '科普', value: '科普' },
    { label: '圈子', value: '圈子' },
])
const navIndex = ref('所有')
const queryParams = ref({
    pageNum: 1, pageSize: 10, businessType: ''
})
const loading = ref(false)
const total = ref(0)
const navClick = (item) => {
    navIndex.value = item.label
    if (item.label == '所有') {
        queryParams.value.businessType = ''
    } else {
        queryParams.value.businessType = item.label
    }
    queryParams.value.pageNum = 1
    getList()
}

const getList = async () => {
    loading.value = true
    const res = await collectList(queryParams.value)
    res.rows.forEach(element => {
        element.createTime = element.createTime.split(' ')[0].replace(/-/g, "/")
        element.avatarImage = '/' + element.avatarImage
    });
    total.value = res.total
    list.value = res.rows
    loading.value = false
}

onMounted(async () => {
    getList()
});
</script>
<style scoped lang="scss">
.right {
    width: calc(100% - 410px);
    height: 100%;

    .header {
        width: 100%;
        padding: 15px 0;
        font-family: Microsoft YaHei;
        font-weight: 400;
        font-size: 18px;
        color: #000000;
        border-bottom: 1px solid #E6E6E6;
    }

    .content {
        width: 100%;
        height: calc(100% - 55px);
        display: flex;
        flex-wrap: wrap;
        justify-content: space-between;
        align-content: flex-start;
        box-sizing: border-box;
        padding: 40px 0 0 0;

        .tabs {
            width: 100%;
            display: flex;
            align-items: center;
            border-bottom: 1px solid #E6E6E6;
            line-height: 2;

            .tabs_items {
                margin-right: 30px;
                color: #A0A0A0;
                font-size: 16px;
                cursor: pointer;
            }

            .tabs_items_active {
                margin-right: 30px;
                color: #000000;
                font-size: 18px;
                cursor: pointer;
            }
        }

        .contents {
            width: 100%;
            height: calc(100% - 109px);
            display: flex;
            justify-content: flex-end;
            align-items: flex-start;
            flex-wrap: wrap;
            align-content: flex-start;
            overflow-y: auto;

            .items {
                width: 100%;
                height: 55px;
                border-bottom: 1px solid #E6E6E6;
                display: flex;
                align-items: center;
                justify-content: space-between;
                padding: 20px 0;
                box-sizing: content-box;
                padding-left: 4px;

                img {
                    width: 65px;
                    height: 51px;
                    border-radius: 5px;
                }

                .right {
                    width: calc(100% - 100px);
                    height: 51px;
                    display: flex;
                    flex-wrap: wrap;

                    .title {
                        width: 100%;
                        font-family: Microsoft YaHei;
                        font-weight: 400;
                        font-size: 14px;
                        color: #000000;
                    }

                    .bottom {
                        width: 100%;
                        display: flex;
                        align-items: center;
                        font-family: Microsoft YaHei;
                        font-weight: 400;
                        font-size: 12px;
                        color: #969696;
                    }
                }
            }
        }

        .paginations {
            width: 100%;
            display: flex;
            align-items: center;
            justify-content: center;
        }

    }
}
</style>